package com.recording.system.sensor;

import java.util.ArrayList;

import com.recording.system.events.RecordingSystemEvent;
import com.recording.system.events.RecordingSystemEventKind;
import com.recording.system.signalsource.SignalSource;

public class EngineWorkSensor extends AbstractSensor{
	public static final String ENGINE_STOPPED = "Engine stopped";
	public static final String ENGINE_STARTED = "Engine started";
	public EngineWorkSensor(int sourceId) {
		super(sourceId);
	}
	public static final double ENGINE_ACTIVE = 1;
	public static final double ENGINE_NOT_ACTIVE = 0;
	private boolean isActive = false;
	@Override
	public void readSignalSource(SignalSource source,
			ArrayList<RecordingSystemEvent> res) {
		boolean newIsActive = source.getValue() != ENGINE_NOT_ACTIVE;
		if (newIsActive != isActive)
		{
			RecordingSystemEvent event;
			if (newIsActive)
			{
				event = new RecordingSystemEvent(RecordingSystemEventKind.START_ENGINE,ENGINE_STARTED);
			}	
			else
			{
				event = new RecordingSystemEvent(RecordingSystemEventKind.STOP_ENGINE,ENGINE_STOPPED);
			}
			res.add(event);
			isActive = newIsActive;
		}
	} 

}
